package com.card.hwatt.assembler;

import java.util.ArrayList;
import java.util.List;

import com.card.hwatt.core.ObjectUtil;
import com.card.hwatt.dto.PageResult;
import com.card.hwatt.entity.Department;

/**
 * 维保单位
 * @author Administrator
 *
 */
public class CompanyAssembler {

	public static PageResult<com.card.hwatt.dto.Company> convert(
			PageResult<Department> list) {
		PageResult<com.card.hwatt.dto.Company> result = new PageResult<com.card.hwatt.dto.Company>();
		List<com.card.hwatt.dto.Company> rows = new ArrayList<com.card.hwatt.dto.Company>();
		result.rows = rows;
		for (Department item : list.rows) {
			com.card.hwatt.dto.Company dto = convert(item);
			rows.add(dto);
		}
		result.total = list.total;
		return result;
	}

	public static com.card.hwatt.dto.Company convert(Department entity) {
		com.card.hwatt.dto.Company dto = new com.card.hwatt.dto.Company();
		ObjectUtil.fieldCopy(entity, dto);
		dto.id = entity.company == null ? null : entity.company.id;
		dto.quantity = entity.company == null ? 0 : entity.company.quantity;
		dto.departmentId = entity.id;
		dto.departmentName = entity.name;
		dto.orderBy = entity.orderBy;
		return dto;
	}

	public static com.card.hwatt.entity.Company convert(
			com.card.hwatt.dto.Company dto) {
		com.card.hwatt.entity.Company entity = new com.card.hwatt.entity.Company();
		ObjectUtil.fieldCopy(dto, entity);
		entity.department = new Department();
		entity.department.id = dto.departmentId;
		return entity;
	}
}
